﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class Controls_head : System.Web.UI.UserControl
{
    public string In_day, In_Total, In_Enterprises, In_Information;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
                top_ad();
                userState();
                proinfo();
        }
    }
    public void top_ad()
    {
        DataTable dt1 = Class1.ExecSel("select ad_Lock,ad_Url,ad_Img,ad_Location,ad_Time from AD where ad_Location=1 order by ad_ID desc");
        if (dt1.Rows[0]["ad_Lock"].ToString() == "0")
        {
            ad1.Text = "<a href=" + dt1.Rows[0]["ad_Url"].ToString() + " target=_blank><img src=" + dt1.Rows[0]["ad_Img"].ToString() + " border=0 width=279 height=61/></a>";
        }
        else
        {
            ad1.Text = "<img src=img/ad1.gif />";
        }

        DataTable dt2 = Class1.ExecSel("select ad_Lock,ad_Url,ad_Img,ad_Location,ad_Time from AD where ad_Location=2 order by ad_ID desc");

        if (dt2.Rows[0]["ad_Lock"].ToString() == "0")
        {
            ad2.Text = "<a href=" + dt2.Rows[0]["ad_Url"].ToString() + " target=_blank><img src=" + dt2.Rows[0]["ad_Img"].ToString() + " border=0 width=407 height=61/></a>";
        }
        else
        {
            ad2.Text = "<img src=img/ad2.gif />";
        }

        DataTable dt3 = Class1.ExecSel("select ad_Lock,ad_Url,ad_Img,ad_Location,ad_Time from AD where ad_Location=3 order by ad_ID desc");
        if (dt3.Rows[0]["ad_Lock"].ToString() == "0")
        {
            ad3.Text = "<a href=" + dt3.Rows[0]["ad_Url"].ToString() + " target=_blank><img src=" + dt3.Rows[0]["ad_Img"].ToString() + " border=0 width=255 height=61/></a>";
        }
        else
        {
            ad3.Text = "<img src=img/ad3.gif />";
        }
    }
    public void userState()
    {
        if (Session["wj_User"] == null)
        {
            USERTATE.Text = "";
        }
        else
        {
            USERTATE.Text = Session["wj_User"].ToString();
            USERMANAGE.Text = "[&nbsp;<a href='Member/' target=_blank>进入后台管理</a>&nbsp;]&nbsp;&nbsp;&nbsp;&nbsp;<a href=Member/uLogout.aspx>退出</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=wjCart.aspx>我的购物车</a>&nbsp;";
        }
    
    }
    public void proinfo()
    {
        DataTable dt = Class1.ExecSel("select * from Product where datediff(hour,p_Time,getDate())" +
      " < 12 And datediff(hour,p_Time,getDate()) >=0 ");
        In_day = dt.Rows.Count.ToString();
        DataTable dt2 = Class1.ExecSel("select * from Product ");
        In_Total = dt2.Rows.Count.ToString();
        DataTable dt3 = Class1.ExecSel("select * from wj_User ");
        In_Enterprises = dt3.Rows.Count.ToString();
        DataTable dt4 = Class1.ExecSel("select * from News ");
        In_Information = dt4.Rows.Count.ToString();

        //DataTable dt5 = Class1.ExecSel("select  Menu_ID,Menu_Name,Menu_Level,Menu_ParentLevel,Menu_Lock from Class where Menu_Level=1 and Menu_Lock=0");
        //drclass.DataSource = dt5;
        //drclass.DataTextField = "Menu_Name";
        //drclass.DataValueField = "Menu_ID";
        //drclass.DataBind();
        //drclass.Items.Add(new ListItem("请选择分类", "0"));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string wTitle = Text1.Value.Trim();
        //string wClass = drclass.SelectedItem.Text;
        Response.Redirect("wjSearch.aspx?wj_KeyWords=" + wTitle + "");

    }
}
